package com.kpf.springcloud.controller;

import com.kpf.springcloud.common.ResultJson;
import com.kpf.springcloud.pojo.KpfUser;
import com.kpf.springcloud.service.ITokenService;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * token相关接口
 *
 * @author shiwen
 * @date 2021/2/28
 */
@RestController
public class KpfTokenController {

    @Autowired
    private ITokenService tokenService;

    @PostMapping("/token/createToken")
    public ResultJson<Boolean> createToken(int userId, int roleType) {
        return ResultJson.ok(tokenService.createToken(userId, roleType));
    }

    /**
     * 校验token
     *
     * @return
     */
    @GetMapping("/token/verifyToken")
    public ResultJson<String> verifyToken() {
        return ResultJson.ok(tokenService.verifyToken());
    }

    @GetMapping("/token/loginOut")
    public ResultJson loginOut() {
        tokenService.loginOut();
        return ResultJson.ok();
    }

}